package com.carbeauty.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 认证控制器
 * 
 * 功能说明:
 * - 登录页面展示
 * - 登出处理
 * - 注册页面（如果需要）
 * - 密码重置页面
 * 
 * @author CarBeauty Team
 */
@Controller
public class AuthController {
    
    /**
     * 登录页面
     */
    @GetMapping("/login")
    public String login(Model model,
                       @RequestParam(value = "error", required = false) String error,
                       @RequestParam(value = "logout", required = false) String logout,
                       @RequestParam(value = "expired", required = false) String expired) {
        
        if (error != null) {
            model.addAttribute("error", "用户名或密码错误");
        }
        
        if (logout != null) {
            model.addAttribute("message", "您已成功退出登录");
        }
        
        if (expired != null) {
            model.addAttribute("error", "会话已过期，请重新登录");
        }
        
        return "auth/login";
    }
    
    /**
     * 注册页面
     */
    @GetMapping("/register")
    public String register(Model model) {
        model.addAttribute("title", "用户注册");
        return "auth/register";
    }
    
    /**
     * 忘记密码页面
     */
    @GetMapping("/forgot-password")
    public String forgotPassword(Model model) {
        model.addAttribute("title", "忘记密码");
        return "auth/forgot-password";
    }
    
    /**
     * 403错误页面
     */
    @GetMapping("/error/403")
    public String accessDenied(Model model) {
        model.addAttribute("title", "访问被拒绝");
        model.addAttribute("message", "您没有权限访问此页面");
        return "error/403";
    }
}
